package com.xio.cloud.controller;

import com.xio.cloud.domain.CommonResult;
import com.xio.cloud.domain.Payment;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: xio
 * @Description: 提供者控制层
 * @Date: 2021/3/23 22:49
 */
@RestController
public class PaymentController {

    @Value("${server.port}")
    private String serverPort;

    public static Map<Long, Payment> dataSource = new HashMap<>();

    static {
        dataSource.put(1L, new Payment(1L, "test11111"));
        dataSource.put(2L, new Payment(2L, "test22222"));
        dataSource.put(3L, new Payment(3L, "test33333"));
    }

    @GetMapping("/payment/get/{id}")
    public CommonResult<Payment> getPayment(@PathVariable Long id) {
        Payment payment = dataSource.get(id);
        if (payment == null) {
            throw new NullPointerException();
        }
        return new CommonResult<>(200, "from serverPort:" + serverPort, payment);
    }

}
